package com.digitaldreamers.spaceshooter.scene;

import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;

import com.digitaldreamers.framework.scene.SceneManager;
import com.digitaldreamers.spaceshooter.Constants;

public class SplashScene extends BaseScene {
	private float mShownTime;
	private Sprite mLogo;
	
	@Override
	public Scene onLoadingSceneLoadAndShown() {
		return null;
	}

	@Override
	public void onLoadingSceneUnloadAndHidden() {
		
	}

	@Override
	public void onLoadScene() {
		this.mResourceManager.loadSplashSceneResources();
		this.mLogo = new Sprite(0, 0, this.mResourceManager.mLogoTextureRegion, this.mVBOM);
		this.mLogo.setPosition(this.mCameraMiddleX, this.mCameraMiddleY);
		this.attachChild(this.mLogo);
	}

	@Override
	public void onShowScene() {
		this.registerUpdateHandler(new IUpdateHandler() {
			@Override
			public void onUpdate(float secondsElapsed) {
				SplashScene.this.mShownTime += secondsElapsed;
				if(SplashScene.this.mShownTime >= Constants.SPLASH_SCENE_SHOWN_TIME) {
					MainMenuScene nextScene = new MainMenuScene();
					SceneManager.getInstance().showScene(nextScene);
				}
			}

			@Override
			public void reset() {
				
			}
		});
	}

	@Override
	public void onHideScene() {
		
	}

	@Override
	public void onUnloadScene() {
		super.onUnloadScene();
		this.mResourceManager.unloadSplashSceneResources();
	}
}
